﻿package com.ouken.activity;




import device_ctr.Dev_logic;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Device09ControlActivity extends Activity {
	private Context context;
	private ImageButton back2;
	private ImageButton back1;
	private ImageButton device09_cmd1;
	private ImageView wifiStatus;
	private TextView cmdStatus;
	private TextView deviceDescrip;
	
	private String deviceSSID;
	private String devicePWD;
	private void initView(){
		context = this;
		back1 = (ImageButton)findViewById(R.id.button09_back1); 
		back2 = (ImageButton)findViewById(R.id.button09_back2); 
		device09_cmd1 = (ImageButton)findViewById(R.id.device09_button_cmd1); 
		wifiStatus = (ImageView)findViewById(R.id.device09_wifi_status); 
		cmdStatus =  (TextView)findViewById(R.id.device09_status); 
		deviceDescrip = (TextView)findViewById(R.id.device09_descrip); 
		
		Intent intent = getIntent(); 
		deviceDescrip.setText(intent.getStringExtra("description").toString());
		wifiStatus.setImageResource(intent.getIntExtra("deviceSignal",0));
		cmdStatus.setText("狀態列...\n無操作");
		
		deviceSSID=intent.getStringExtra("deviceSSID").toString();
		devicePWD=intent.getStringExtra("devicePWD").toString();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.device09ctrl);
		initView();
		
		back1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Device09ControlActivity.this.finish();
			}
		});
		
		back2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Device09ControlActivity.this.finish();
			}
		});
		
		device09_cmd1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.e("Duan", "cmd1 is click");
				Dev_logic logic_er=new Dev_logic();
				String result=logic_er.set_device(devicePWD, "00000001");
				if (result.startsWith("OK")==true){
					cmdStatus.setText(getString(R.string.device_07_st_1));
				}
				else{
					cmdStatus.setText(getString(R.string.device_st_error));
				}
				Log.e("Duan", result);
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return true;
	}

}
